const {app, BrowserWindow}  = require("electron");
const path = require("path");


let icon = path.resolve(__dirname, "../asserts/img/icon.ico");

let isDevelopment = process.env.NODE_ENV === "development";

const load_url = isDevelopment ? "http://localhost:8099"
                               :  `file://${path.resolve(__dirname, '../dist/index.html')}`;

function createWindow() {
    const win = new BrowserWindow({
        width: 1440,
        height: 800,
        frame: false,
        title: "小蜘蛛",
        icon: icon,
        webPreferences: {
            nodeIntegration: true // 是否集成node
        }
    });
    win.loadURL(load_url);
    if(isDevelopment)
        win.webContents.openDevTools({mode:"undocked"});
    win.show(false);
    win.once("ready-to-show", () => {
        win.show(true);
    })
}
app.whenReady().then(createWindow);

app.on('window-all-closed', () => {
    // 在 macOS 上，除非用户用 Cmd + Q 确定地退出，
    // 否则绝大部分应用及其菜单栏会保持激活。
    if (process.platform !== 'darwin') {
        app.quit()
    }
});

app.on('activate', () => {
    // 在macOS上，当单击dock图标并且没有其他窗口打开时，
    // 通常在应用程序中重新创建一个窗口。
    if (BrowserWindow.getAllWindows().length === 0) {
        createWindow();
    }
});
